<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="职位" prop="UserTypeName">
        <el-input v-model="ruleForm.UserTypeName"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >立即添加</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import axios from '@/util/axios.js'
export default {
  data() {
    return {
      ruleForm: {
        UserTypeName: "",
      },
      rules: {
        UserTypeName: [
          { required: true, message: "请输入职位", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
           axios.post("api/UserTypes/Insert",this.ruleForm).then((res)=>{
             this.$emit("add-ok")
            if(res.data.Code==0){
                this.$emit("add-ok")
            }else{
                this.$message("职位信息重复")
            }
           })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
  },
  created() {},
};
</script>
<style>
</style>